#include <iostream>
#include <vector>
using namespace std;

void quickSort(vector<int>& res,int head,int tail) {
	if (tail < head) return;
	int tmp = res[head];
	int l = head;
	int r = tail;
	while (l < r) {
		while (l < r && res[r] <= tmp) {
			r--;
		}
		while (l < r && res[l] >= tmp) {
			l++;
		}
		if (l < r) {
			swap(res[l], res[r]);
		}
	}
	res[head] = res[r];
	res[r] = tmp;
	quickSort(res, head, tail - 1);
	quickSort(res, head + 1, tail);
}

int main() {
	int arr[] = { 3,2,4,6,1,7,9,8 };
	vector<int> res(arr, arr + 8);
	int len = res.size();
	quickSort(res,0,len - 1);

	vector<int>::iterator ite = res.begin();
	for (; ite != res.end(); ite++) {
		cout << *ite << " ";
	}
	system("pause");
	return 0;
}
